/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.U.
 */
package es.silenus.detecta.batch.writer;

import es.silenus.detecta.dao.SurveyAnswerHeaderImportedDAO;

import es.silenus.detecta.model.SurveyAnswerHeaderImported;

import org.springframework.batch.item.ItemWriter;

import java.util.List;


/**
 * Survey answer header imported writer.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 24-ago-2009 17:34:19
 */
public class SurveyAnswerHeaderImportedWriter implements ItemWriter<SurveyAnswerHeaderImported> {
	/**
	 * The survey answer header imported DAO.
	 */
	private SurveyAnswerHeaderImportedDAO surveyAnswerHeaderImportedDAO;

	/**
	 * Sets the survey answer header imported DAO.
	 *
	 * @param surveyAnswerHeaderImportedDAO the survey answer header imported DAO.
	 */
	public void setSurveyAnswerHeaderImportedDAO(final SurveyAnswerHeaderImportedDAO surveyAnswerHeaderImportedDAO) {
		this.surveyAnswerHeaderImportedDAO = surveyAnswerHeaderImportedDAO;
	}

	/**
	 * Process the supplied data element. Will not be called with any null items in normal operation.
	 *
	 * @param items the items.
	 *
	 * @throws Exception if there are errors. The framework will catch the exception and convert or rethrow it as
	 * 				 appropriate.
	 */
	public void write(List<?extends SurveyAnswerHeaderImported> items) throws Exception {
		if(items != null) {
			for(SurveyAnswerHeaderImported item : items) {
				surveyAnswerHeaderImportedDAO.save(item);
			}
		}
	}
}
